// pages/pay-success/pay-success.js
import {check} from '../../../util/identityCheck'
import Dialog from '../../../miniprogram_npm/@vant/weapp/dialog/dialog'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    desc: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.redpacket )
    if(!check())return
    this.setData({
      desc: options.desc
    })
    if (+options.redpacket > 0) {
      Dialog.alert({
        message: `恭喜你${options.redpacket}元红包已到账 \n 邀请好友发布页可获得红包哦~`,
        confirmButtonText: '邀请拿红包',
        cancelButtonText: '查看红包',
        showCancelButton: true,
        cancelButtonColor: '#23DEAF',
        confirmButtonOpenType: 'share'
      }).then(() => {

      }).catch(() => {
        wx.requestSubscribeMessage({
          tmplIds: ['-DHKrW9DRvbg3sEoVRYtcRxRyr-kYzyTN-9BNCY89rI', 'b7FIjt52cUMvTClpMJKJLe8lzi4rnQsWlUc7D5VYGoA', 'PbmE0p7hgtUXlZcUEgR_qBcP3tMhbe1-_wKNw7CkoZY'],
          complete (res) {
            wx.redirectTo({
              url: `/packageA/pages/my-redpacket/my-redpacket`
            })
          }
        })
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  toHome() {
    wx.switchTab({
      url: '/pages/main/main'
    })
  },

  sendNotify () {
    // 发送微信订阅消息推送 审核通知
    const that = this
    wx.requestSubscribeMessage({
      tmplIds: ['-DHKrW9DRvbg3sEoVRYtcRxRyr-kYzyTN-9BNCY89rI', 'b7FIjt52cUMvTClpMJKJLe8lzi4rnQsWlUc7D5VYGoA', 'PbmE0p7hgtUXlZcUEgR_qBcP3tMhbe1-_wKNw7CkoZY'],
      complete (res) {
        that.toHome()
      }
    })
  },
  onShareAppMessage: function () {
    return {
      title: '闲买足疗人',
      imageUrl: 'https://m.xianmaiyangsheng.com/xcxImg/image/zuliaoren/redpacketshare.png',
      path: `/pages/main/main?id=${this.data.id}&otherId=${wx.getStorageSync('userInfo').user_id}&time=${+new Date()}`
    }
  }
})